﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace SplenetiX
{
    class Hud
    {
        Vector2 position;
        static public SpriteFont spriteFont;
        Personnage player;
        Ennemi ennemi;
        string text;
        float health;
        Texture2D fondHud;

        //new interface
        Texture2D Vie_line;
        Rectangle Position_vie;
        Texture2D Mana_line;
        Rectangle Position_mana;
        Texture2D Gun_Normal, Gun_Highlight, Magic_Normal, Magic_Highlight, Gun_Stat, Magic_stat;
        Vector2 Gun_position, Magic_position;

        Texture2D Vie_ico;
        Vector2 Vie_ico_position;
        Texture2D Mana_ico;
        Vector2 Mana_ico_position;

        Texture2D FondInterface;
        Vector2 FondInterface_position;

        public Hud(Vector2 position, ref Personnage player)
        {
            this.position = position;
            this.player = player;
        }

        public Hud(Vector2 position, Ennemi ennemi)
        {
            this.position = position;
            this.ennemi = ennemi;
        }

        public void Load(ContentManager contentManager, string assetName)
        {
            spriteFont = contentManager.Load<SpriteFont>(assetName);
            fondHud = contentManager.Load<Texture2D>("Hud_Interface//bg_hud");

            Vie_ico = contentManager.Load<Texture2D>("Hud_Interface//Vie_ico");
            Mana_ico = contentManager.Load<Texture2D>("Hud_Interface//Mana_ico");

            Vie_line = contentManager.Load<Texture2D>("Hud_Interface//Vie_line");
            Mana_line = contentManager.Load<Texture2D>("Hud_Interface//Mana_line");

            Gun_Normal = contentManager.Load<Texture2D>("Hud_Interface//Gun_N");
            Gun_Highlight = contentManager.Load<Texture2D>("Hud_Interface//Gun_H");
            Magic_Normal = contentManager.Load<Texture2D>("Hud_Interface//Magic_N");
            Magic_Highlight = contentManager.Load<Texture2D>("Hud_Interface//Magic_H");
            FondInterface = contentManager.Load<Texture2D>("Hud_Interface//FondInterface");
        }

        public void Update()
        {
            /* Hud Debug */
            health = player.Health;
            text = "Vie : " + health;
            text += "\r\nCoord : x = " + player.Position.X + "; y = " + player.Position.Y;
            text += "\r\nIsDie = " +player.IsDie;
            text += "\r\nProjectile : " + player.Projectiles.Count;
            text += "\r\nVolume : " + (int)(SoundEngine.Volume * 100) + " %";

            /* Hud Perso */
            Position_vie = new Rectangle(30, 15, (int)health * 3, 12);
            Position_mana = new Rectangle(30, 35,/*a dmodifier en mana*/ (int)health * 3, 12);

            Magic_position = new Vector2(40,55);
            Gun_position = new Vector2(80,55);

            Vie_ico_position = new Vector2(10,15);
            Mana_ico_position = new Vector2(10,35);

            FondInterface_position = new Vector2(0,0);

            sort_H();
        }

        public void UpdateEnnemi(SpriteAnimation AnimEnnemi)
        {
            health = ennemi.Health;
            text = "Vie : " + health;
            text += "\r\nCoord : x = " + ennemi.Position.X + "; y = " + ennemi.Position.Y;
            text += "\r\nAnimEnnemi.Annimation = "+ AnimEnnemi.Animation;
            text += "\r\nDirection =" + ennemi.Direction;
        }

        public void Draw(SpriteBatch batch)
        {
            if (ServiceHelper.Get<IKeyboardService>().IsKeyDown(Keys.D))
            {                
                batch.Draw(fondHud, new Vector2(0, 0), Color.White);
                batch.DrawString(spriteFont, text, position, Color.White);
            }
            else
            {
                batch.Draw(FondInterface, FondInterface_position, Color.White);

                batch.Draw(Vie_ico,Vie_ico_position,Color.White);
                batch.Draw(Vie_line, new Rectangle(30, 15, 300, 12), Color.SlateGray);
                batch.Draw(Vie_line, Position_vie, Color.White);


                batch.Draw(Mana_ico, Mana_ico_position, Color.White);
                batch.Draw(Mana_line, new Rectangle(30, 35, 300, 12), Color.SlateGray);
                batch.Draw(Mana_line, Position_mana, Color.White);         
       
                batch.Draw(Gun_Stat, Magic_position, Color.White);
                batch.Draw(Magic_stat, Gun_position, Color.White);
            }
        }

        public void /*a remplacer par "sort"*/ sort_H()
        {
            if (ServiceHelper.Get<IKeyboardService>().IsKeyDown(Keys.NumPad0))
            {
                Gun_Stat = Gun_Highlight;
                Magic_stat = Magic_Normal;
            }
            else
            {
                Gun_Stat = Gun_Normal;
                Magic_stat = Magic_Highlight;
            }
        }
    }
}
